package threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 通过线程池创建线程
 */
public class Test1 {
    public static void main(String[] args) {
        // 1.创建服务，创建线程池
        ExecutorService service = Executors.newFixedThreadPool(10);

        // 2.执行
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());

        // 3.关闭线程池
        service.shutdown();
    }
}

class MyThread implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}

/*
    pool-1-thread-1
    pool-1-thread-4
    pool-1-thread-3
    pool-1-thread-2
 */
